package com.wj.Pic;

import org.junit.Test;

import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;
/**
 * @author WangJin
 * @version 1.0
 * @date 2022/1/27 18:04
 */

public class pc {
    public void drawPic(String picPath) {
        BufferedImage img;
        String base = "啊哈";
        try {
            img = ImageIO.read(new File(picPath));
            int width = img.getWidth();
            int height = img.getHeight();
            for(int y = 0; y<height;y+=6) {
                for (int x = 0;x<width;x+=6) {
                    int pixel = img.getRGB(x, y);
                    int r = (pixel >> 16) & 0xFF;
                    int g = (pixel >> 8) & 0xFF;
                    int b = pixel & 0xFF;
                    double gray = 0.299f * r + 0.578f * g + 0.114f * b;
                    int index = (int) Math.floor(gray*base.length()/256);
                    char symbol = base.charAt(index);
                    System.out.print(symbol);
                }
                System.out.println();

            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }



    }

    @Test
    public void test() {
        pc picture = new pc();
        picture.drawPic("D:\\io\\pc\\1.jpg");
    }

}